home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / TEX-UTIL / DVIPS_55 / dvips / tex / lpro next >
Text File  |  1994-03-26  |  11KB  |  343 lines

  1. % The following defines procedures assumed and used by program "dvips"
  2. % and must be downloaded or sent as a header file for all TeX jobs.
  3. % Originated by Neal Holtz, Carleton University, Ottawa, Canada
  4. %      <holtz@cascade.carleton.cdn>
  5. %      June, 1985
  6. %
  7. %   Hacked by tgr, July 1987, stripped down to bare essentials,
  8. %   plus a few new commands for speed.
  9. %
  10. %   Hacked by don, December 1989, to give characters top down and to
  11. %   remove other small nuisances; merged with tgr's compression scheme
  12. %
  13. % To convert this file into a downloaded file instead of a header
  14. % file, uncomment all of the lines beginning with %-%
  15. %
  16. %   To observe available VM, uncomment the following.
  17. %   (The first ten lines define a general 'printnumber' routine.)
  18. %
  19. % /VirginMtrx 6 array currentmatrix def
  20. % /dummystring 20 string def
  21. % /numberpos 36 def
  22. % /printnumber { gsave VirginMtrx setmatrix
  23. %   /Helvetica findfont 10 scalefont setfont
  24. %   36 numberpos moveto
  25. %   /numberpos numberpos 12 add def
  26. %   dummystring cvs show
  27. %   grestore
  28. %   } bind def
  29. % /showVM { vmstatus exch sub exch pop printnumber } def
  30. % /eop-aux { showVM } def
  31. %
  32. %-%0000000             % Server loop exit password
  33. %-%serverdict begin exitserver
  34. %-%  systemdict /statusdict known
  35. %-%  {statusdict begin 9 0 3 setsccinteractive /waittimeout 300 def end}
  36. %-% if
  37.  
  38. /TeXDict 250 dict def   % define a working dictionary ( IBM: color - 200->250 )
  39. TeXDict begin           % start using it.
  40. /N {def} def
  41. /B {bind def} N
  42. /S {exch} N
  43. /X { S N } B
  44. /TR {translate} N
  45.  
  46. % The output of dvips assumes pixel units, Resolution/inch, with
  47. % increasing y coordinates corresponding to moving DOWNWARD.
  48. % The PostScript default is big point units (bp), 72/inch, with
  49. % increasing y coordinates corresponding to moving UP; the
  50. % following routines handle conversion to dvips conventions. 
  51.  
  52. % Let the PostScript origin be (xps,yps) in dvips coordinates.
  53.  
  54. /isls false N
  55. /vsize 11 72 mul N
  56. /hsize 8.5 72 mul N
  57. /landplus90 { false } def % make this true to flip landscape
  58.  
  59. /@rigin                 % -xps -yps @rigin -   establishes dvips conventions
  60.   { isls { [ 0 landplus90 { 1 -1 } { -1 1 } ifelse 0 0 0 ] concat } if
  61.     72 Resolution div 72 VResolution div neg scale
  62.     isls { landplus90 { VResolution 72 div vsize mul 0 exch }
  63.                       { Resolution -72 div hsize mul 0 } ifelse TR } if
  64.     Resolution VResolution vsize -72 div 1 add mul TR
  65. % As bad as setmatrix is, it is better than misalignment.
  66.     [ matrix currentmatrix
  67.        { dup dup round sub abs 0.00001 lt {round} if } forall
  68.        round exch round exch
  69.     ] setmatrix } N
  70.  
  71. /@landscape { /isls true N } B
  72.  
  73. /@manualfeed
  74.    { statusdict /manualfeed true put
  75.    } B
  76.  
  77.         % n @copies -   set number of copies
  78. /@copies
  79.    { /#copies X
  80.    } B
  81.  
  82. % Bitmap fonts are called Fa, Fb, ..., Fz, F0, F1 . . . Ga . . .
  83. % The calling sequence for downloading font foo is
  84. %           /foo df charde1 ... chardefn E 
  85. % where each chardef is
  86. %           <hexstring> wd ht xoff yoff dx charno D 
  87. %  or       <hexstring> wd ht xoff yoff dx I
  88. %  or       <hexstring> charno D
  89. %  or       <hexstring> I
  90.  
  91. /FMat [1 0 0 -1 0 0] N
  92. /FBB [0 0 0 0] N
  93.  
  94. /nn 0 N /IE 0 N /ctr 0 N
  95. /df-tail       % id numcc maxcc df-tail -- initialize a new font dictionary
  96.   {
  97. %   dmystr 2 fontname cvx (@@@@) cvs putinterval  % put name in template
  98.     /nn 8 dict N              % allocate new font dictionary
  99.     nn begin
  100.         /FontType 3 N
  101.     /FontMatrix fntrx N
  102.     /FontBBox FBB N
  103.         string /base X
  104.         array /BitMaps X
  105.         /BuildChar {CharBuilder} N
  106.         /Encoding IE N
  107.         end
  108.     dup { /foo setfont }          %  dummy macro to be filled in
  109.        2 array copy cvx N         %  have to allocate a new one
  110.     load                          %  now we change it
  111. %      0 dmystr 6 string copy       %  get a copy of the font name
  112.        0 nn put
  113. %      cvn cvx put                  %  and stick it in the dummy macro
  114.     /ctr 0 N                      %  go, count, and etc.
  115.     [                               %  start next char definition
  116.   } B
  117. /df {
  118.    /sf 1 N
  119.    /fntrx FMat N
  120.    df-tail
  121. } B
  122. /dfs { div /sf X
  123.    /fntrx [ sf 0 0 sf neg 0 0 ] N
  124.    df-tail
  125. } B
  126.  
  127. /E { pop nn dup definefont setfont } B
  128.  
  129. % the following is the only character builder we need.  it looks up the
  130. % char data in the BitMaps array, and paints the character if possible.
  131. % char data  -- a bitmap descriptor -- is an array of length 6, of
  132. %          which the various slots are:
  133.  
  134. /ch-width {ch-data dup length 5 sub get} B % the number of pixels across
  135. /ch-height {ch-data dup length 4 sub get} B % the number of pixels tall
  136. /ch-xoff  {128 ch-data dup length 3 sub get sub} B % num pixels right of origin
  137. /ch-yoff  {ch-data dup length 2 sub get 127 sub} B % number of pixels below origin
  138. /ch-dx  {ch-data dup length 1 sub get} B     % number of pixels to next character
  139. /ch-image {ch-data dup type /stringtype ne
  140.       { ctr get /ctr ctr 1 add N } if
  141.    } B                        % the hex string image, or array of same
  142. %      /id ch-image N                          % image data
  143. /id 0 N /rw 0 N /rc 0 N /gp 0 N /cp 0 N /G 0 N /sf 0 N
  144.  
  145. /CharBuilder    % fontdict ch Charbuilder -     -- image one character
  146.      {save 3 1 roll S dup /base get 2 index get S /BitMaps get S get
  147.       /ch-data X pop
  148.       /ctr 0 N
  149.       ch-dx 0 ch-xoff ch-yoff ch-height sub
  150.       ch-xoff ch-width add ch-yoff
  151.       setcachedevice
  152.       ch-width ch-height true
  153.       [1 0 0 -1 -.1 ch-xoff sub ch-yoff .1 sub]
  154. % begin code for uncompressed fonts only
  155.       {ch-image} imagemask
  156.       restore
  157.   } B
  158. % end code for uncompressed fonts only
  159. % % here's the alternate code for unpacking compressed fonts
  160. %      /id ch-image N                          % image data
  161. %      /rw ch-width 7 add 8 idiv string N      % row, initially zero
  162. %      /rc 0 N                                 % repeat count
  163. %      /gp 0 N                                 % image data pointer
  164. %      /cp 0 N                                 % column pointer
  165. %      { rc 0 ne { rc 1 sub /rc X rw } { G } ifelse } imagemask
  166. %    restore
  167. % } B
  168. % /G { { id gp get /gp gp 1 add N
  169. %   dup 18 mod S 18 idiv pl S get exec } loop } B
  170. % /adv { cp add /cp X } B
  171. % /chg { rw cp id gp 4 index getinterval putinterval
  172. %         dup gp add /gp X adv } B
  173. % /nd { /cp 0 N rw exit } B
  174. % /lsh { rw cp 2 copy get dup 0 eq { pop 1 } { dup 255 eq { pop 254 }
  175. %     { dup dup add 255 and S 1 and or } ifelse } ifelse put 1 adv } B
  176. % /rsh { rw cp 2 copy get dup 0 eq { pop 128 } { dup 255 eq { pop 127 }
  177. %     { dup 2 idiv S 128 and or } ifelse } ifelse put 1 adv } B
  178. % /clr { rw cp 2 index string putinterval adv } B
  179. % /set { rw cp fillstr 0 4 index getinterval putinterval adv } B
  180. % /fillstr 18 string 0 1 17 { 2 copy 255 put pop } for N
  181. % /pl [
  182. %    { adv 1 chg }
  183. %    { adv 1 chg nd }
  184. %    { 1 add chg }
  185. %    { 1 add chg nd }
  186. %    { adv lsh }
  187. %    { adv lsh nd }
  188. %    { adv rsh }
  189. %    { adv rsh nd }
  190. %    { 1 add adv }
  191. %    { /rc X nd }
  192. %    { 1 add set }
  193. %    { 1 add clr }
  194. %    { adv 2 chg }
  195. %    { adv 2 chg nd }
  196. %    { pop nd } ] dup { bind pop } forall N
  197. % % end of code for unpacking compressed fonts
  198.  
  199.                % in the following, the font-cacheing mechanism requires that
  200.                 % a name unique in the particular font be generated
  201.  
  202. /D            % char-data ch D -    -- define character bitmap in current font
  203.   { /cc X
  204.     dup type /stringtype ne {]} if
  205.     nn /base get cc ctr put
  206.     nn /BitMaps get S ctr S
  207.     sf 1 ne {
  208.        dup dup length 1 sub dup 2 index S get sf div put
  209.     } if
  210.     put
  211.     /ctr ctr 1 add N
  212.   } B
  213.  
  214. /I            % a faster D for when the next char follows immediately
  215.   { cc 1 add D } B
  216.  
  217. /bop           % %t %d bop -  -- begin a brand new page, %t=pageno %d=seqno
  218.   {
  219.     userdict /bop-hook known { bop-hook } if
  220.     /SI save N
  221.     @rigin
  222. %
  223. %   Now we check the resolution.  If it's correct, we use RV as V,
  224. %   otherwise we use QV.
  225. %
  226.     0 0 moveto
  227.     /V matrix currentmatrix
  228.     dup 1 get dup mul exch 0 get dup mul add .99 lt
  229.     {/QV} {/RV} ifelse load def
  230.     pop pop
  231.   } N
  232.  
  233. /eop           % - eop -              -- end a page
  234.   { % eop-aux  % -- to observe VM usage
  235.     SI restore
  236.     showpage
  237.     userdict /eop-hook known { eop-hook } if
  238.   } N
  239.  
  240. /@start         % hsz vsz mag dpi vdpi name @start -   -- start everything
  241.   {
  242.     userdict /start-hook known { start-hook } if
  243.     pop % the job name string is used only by start-hook
  244.     /VResolution X
  245.     /Resolution X
  246.     1000 div /DVImag X
  247.     /IE 256 array N
  248.     0 1 255 {IE S 1 string dup 0 3 index put cvn put} for
  249.     65781.76 div /vsize X
  250.     65781.76 div /hsize X
  251.   } N
  252.  
  253. /p {show} N        %  the main character setting routine
  254.  
  255. /RMat [ 1 0 0 -1 0 0 ] N % things we need for rules
  256. /BDot 260 string N
  257. /rulex 0 N /ruley 0 N
  258. /v {                   % can't use ...fill; it makes rules too big
  259.    /ruley X /rulex X
  260.    V
  261. } B
  262. %
  263. %   What we need to do to get things to work here is tragic.
  264. %
  265. /V {} B /RV
  266. %
  267. %   Which do we use?  The first if we are talking to Display
  268. %   PostScript, the latter otherwise.
  269. %
  270. statusdict begin /product where
  271.    { pop product dup length 7 ge
  272.       { 0 7 getinterval dup (Display) eq exch 0 4 getinterval (NeXT) eq or }
  273.       { pop false } ifelse }
  274.    { false } ifelse end
  275. { {
  276.    gsave
  277.       TR -.1 .1 TR 1 1 scale rulex ruley
  278.       false RMat { BDot } imagemask
  279.    grestore
  280. } }
  281. { {
  282.    gsave
  283.       TR -.1 .1 TR rulex ruley scale 1 1
  284.       false RMat { BDot } imagemask
  285.    grestore
  286. } } ifelse B
  287. %
  288. %   We use this if the resolution doesn't match.
  289. %
  290. /QV {
  291.    gsave
  292.       newpath transform round exch round exch itransform moveto
  293.       rulex 0 rlineto 0 ruley neg rlineto
  294.       rulex neg 0 rlineto fill
  295.    grestore
  296. } B
  297. %
  298. /a { moveto } B    % absolute positioning
  299. /delta 0 N         % we need a variable to hold space moves
  300. %
  301. %   The next ten macros allow us to make horizontal motions that
  302. %   are within 4 of the previous horizontal motion with a single
  303. %   character.  These are typically used for spaces.
  304. %
  305. /tail { dup /delta X 0 rmoveto } B
  306. /M { S p delta add tail } B
  307. /b { S p tail } B      % show and tail!
  308. /c { -4 M } B
  309. /d { -3 M } B
  310. /e { -2 M } B
  311. /f { -1 M } B
  312. /g { 0 M } B
  313. /h { 1 M } B
  314. /i { 2 M } B
  315. /j { 3 M } B
  316. /k { 4 M } B
  317. %
  318. %   These next allow us to make small motions (-4..4) cheaply.
  319. %   Typically used for kerns.
  320. %
  321. /w { 0 rmoveto } B
  322. /l { p -4 w } B
  323. /m { p -3 w } B
  324. /n { p -2 w } B
  325. /o { p -1 w } B
  326. /q { p 1 w } B
  327. /r { p 2 w } B
  328. /s { p 3 w } B
  329. /t { p 4 w } B
  330. %
  331. %  x is good for small vertical positioning.
  332. %  And y is good for a print followed by a move.
  333. %
  334. /x { 0 S rmoveto } B
  335. /y { 3 2 roll p a } B
  336. %
  337. %   The bos and eos commands bracket sections of downloaded characters.
  338. %
  339. /bos { /SS save N } B
  340. /eos { SS restore } B
  341.  
  342. end  % revert to previous dictionary
  343.